var sLang = $("html").attr("lang");

var navigationLinks = {
	'next':  { keyCode: 0x27 },
	'prev':  { keyCode: 0x25 },
	'up':    { keyCode: 0x26 },
	'down':  { keyCode: 0x28 },
	'start': { keyCode: 0x24 }
}

/*
* Popup block v2.0
*/
var popup_block = function (options) {

	var that = {};

	var keep = false,
	    documentClickHandler,
	    documentKeyDownHandler;


	that.hide = function (event) {
		if (keep) {
			keep = false;
			return;
		}

		if (options.onBlockHide) {
			options.onBlockHide(options);
		}

		if (options.fader) {
			options.fader.addClass("hidden");
		}
		options.container.addClass("hidden");

		$(document).unbind("click", documentClickHandler);
		$(document).unbind("keydown", documentKeyDownHandler);
	};


	that.cancel = function (event) {
		var code = event.keyCode ? event.keyCode : event.which ? event.which : null;
		if (code === 27) {
			that.hide(event);
		}
	};


	that.show = function (event) {

		options.container.removeClass("hidden");
		if (options.onBlockShow) {
			options.onBlockShow(options);
		}

		if (options.fader) {
			options.fader
				.removeClass("hidden")
				.click(function (event) {
					that.toggle(event);
				});
		}

		documentClickHandler = function (event) {
			if (!event.which || event.which !== 1)
				keep = true;

			that.hide(event);
		};

		documentKeyDownHandler = function (event) {
			that.cancel(event);
		};

		$(document).click(documentClickHandler);
		$(document).keydown(documentKeyDownHandler);
	};


	that.toggle = function (event) {

		event.preventDefault();
		event.stopPropagation();

		if (options.container.hasClass("hidden")) {
			that.show(event);
		} else {
			that.hide(event);
		}
	};


	options.container.click(function (event) {
		keep = true;
	});

	options.link.click(function (event) {
		that.toggle(event);
	});

	if (options.close) {
		options.close.click(function (event) {
			that.toggle(event);
		});
	}

	return that;
};

$(function(){
	$('link').each(function() {
		var rel = $(this).attr('rel');
		if (navigationLinks[rel]) navigationLinks[rel].href = $(this).attr('href');
	});

	$(document).keydown(function(event) {
		if (!event.ctrlKey) return true;

		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : null;

		for (var rel in navigationLinks) {
			if (navigationLinks[rel].keyCode == keyCode && navigationLinks[rel].href) {
				document.location = navigationLinks[rel].href;
			}
		}
	});
});


/* Float Connection Btn */
function getScrollTop(){
	if(typeof pageYOffset!= 'undefined'){
		//most browsers
		return pageYOffset;
	}
	else{
		var B= document.body; //IE 'quirks'
		var D= document.documentElement; //IE with doctype
		D= (D.clientHeight)? D: B;
		return D.scrollTop;
	}
}